<%@ page import="domain.Contact,  domain.ContactGroup, domain.Address, domain.PhoneNumber, domain.Entreprise "%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<jsp:include page="topHtml.jsp" />
		<%
			Contact contact = (Contact) request.getAttribute("contact");
		    Object[] phones =  contact.getPhones().toArray(); 
			Object[] groups = (Object[])request.getAttribute("groups"); 
			Object[] contactGroups = contact.getGroups().toArray();
	    %>
		<html:form action="/ModifyContact" >
		<div id="errors" >
			<html:errors />
		</div>
			<input type="hidden" name="id" size="25" value="<%=contact.getContactId()%>" />
			<input type="hidden" name="version" value="<%=contact.getVersion()%>" />
			<label><bean:message key="contact.firstname" />: </label><html:text property="firstName" size="25" value="<%=contact.getFirstName()%>" /> <br />
				 <label><bean:message key="contact.lastname" />: </label><html:text property="lastName" size="30" value="<%=contact.getLastName()%>" /> <br />
				 <label><bean:message key="contact.email" />: </label><html:text property="email" size="25" value="<%=contact.getEmail()%>" /> <br>
				 <% Address addr = contact.getAdd(); %>
				 		<label for="street"><bean:message key="address.street" />:</label> <html:text property="street" size="25" value="<%= addr.getStreet() %>" /> <br />
			<label for="zip"><bean:message key="address.zip" />:</label> <html:text property="zip" size="30" value="<%= addr.getZip() %>" /> <br />
			<label for="city"><bean:message key="address.city" />: </label> <html:text property="city" size="25" value="<%= addr.getCity() %>" /> <br />
			<label for="country"><bean:message key="address.country" />: </label><html:text property="country" size="25" value="<%= addr.getCountry() %>" /> <br />
			<br /> 
			<label for="group">Group: </label>
			<select name="groupIds" multiple="multiple">			
		<% for( Object obj : groups) { %>
				<% ContactGroup cg = (ContactGroup) obj; 
					String selected = "";
				%>
				<%
					for(ContactGroup group : contact.getGroups()) {
						if(cg.getGroupId() == group.getGroupId()) {
							selected = " selected";
						}
					}
				%>
				<option value="<%= cg.getGroupId() %>" <%= selected  %>><%= cg.getGroupName() %></option>
			<% } %>
			</select> <br /><br />
		  <% if ( phones.length == 0) {%>
	<span>This contact doesn't have any phones.</span>
	<% } else { %>
		<table class="list-phones">
			<tr>
				<th>Phone kind</th>
				<th>Phone Number</th>
				<th>Actions</th>
			</tr>
			<% for( Object obj : phones) { %>
				<% PhoneNumber phone = (PhoneNumber) obj; %>
				<tr>
				<td><%= phone.getPhoneKind()%></td>
				<td><%= phone.getPhoneNumber()%></td>
				<td>
					<ul class="boite-controle">
						<li><a href="PhoneModification.do?contactId=<%= contact.getContactId() %>&phoneId=<%= phone.getPhoneId() %>" class="lien"><bean:message key="modify.link" /></a></li>
						<li><a href="PhoneDeletionWithConfirmation.do?contactId=<%= contact.getContactId() %>&phoneId=<%= phone.getPhoneId() %>" class="lien"><bean:message key="delete.link" /></a></li>
					</ul>
				</td>
			</tr>
			<% } %>
		</table>
		<% } %>
		<ul class="boite-controle">
				<li><a href="PhoneCreation.do?contactId=<%= contact.getContactId() %>" class="lien"><bean:message key="phone.add.link" /></a></li>
			</ul>
		  <br /><br /> 
			<% if(contact instanceof Entreprise ){ %>
			<label for="numSiret"><bean:message key="contact.numSiret" />: </label><input type="text" name="numSiret" size="25" value="<%= ((Entreprise)contact).getNumSiret() %>" />
			<% } %>
			 <br /><br />
			<html:submit styleClass="button"><bean:message key="contact.modify.link" /></html:submit>
			<html:reset	styleClass="button"><bean:message key="reset.link" /></html:reset>
		</html:form>
	
<jsp:include page="bottomHtml.jsp" />